#ifndef _DYNAMIC_Q_OBJECT_H
#define _DYNAMIC_Q_OBJECT_H

#include <QObject>
#include <QHash>
#include <QList>
#include <QByteArray>

#include <objc/objc-api.h>

class VirtualSlot
{
public:
    VirtualSlot(SEL selector);
    ~VirtualSlot();
    virtual void call(QObject *sender, void **arguments) = 0;
    const char *slotRepresentation();
    void setTarget(id target);
    
protected:
    SEL sel;
    id target;
    IMP imp;
};

class DynamicQObject: public QObject
{
public:
    DynamicQObject(QObject *parent = 0) : QObject(parent) { }

    virtual int qt_metacall(QMetaObject::Call c, int _id, void **arguments);

    //bool emitDynamicSignal(char *signal, void **arguments);	
    bool connect(QObject *obj, const char *signal, id objcObj, VirtualSlot *slot);
    //bool connectDynamicSignal(char *signal, QObject *obj, char *slot);

private:
    QHash<QByteArray, int> slotIndices;
    QList<VirtualSlot *> slotList;
    QHash<QByteArray, int> signalIndices;
};

#endif /* _DYNAMIC_Q_OBJECT_H */
